import java.util.Arrays;

public class InsertSort {
    static int[] insertSort(int[] arr){
        for (int i = 1; i < arr.length; i++) {
            int j=i,target=arr[i];
            while (j>0&&target<arr[j-1]){
                arr[j] = arr[j-1];
                j --;
            }
            arr[j] = target;
        }
        return arr;
    }

    public static void main(String[] args) {
        System.out.println( Arrays.toString(insertSort(new int[]{9, 8, 5, 6, 7, 5, 6, 2, 4, 98, 5, 87, 2, 6, 2, 0, 5, 5, 9})));
    }

}
